package com.doctor.adapter;

import java.util.List;

import com.doctor.bean.DiseaseRecordBean;
import com.doctor.ui.R;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class DiseaseRecordAdapter extends BaseAdapter{

	/**
	 * 病历与体检资料adapter
	 */
	
	private Context context;
	private List<DiseaseRecordBean> beanList;

	public DiseaseRecordAdapter(Context context,List<DiseaseRecordBean> beanList){
		this.context=context;
		this.beanList=beanList;
	}
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return beanList.size();
	}

	@Override
	public DiseaseRecordBean getItem(int arg0) {
		// TODO Auto-generated method stub
		return beanList.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}
	
	public void clear(){
		beanList.clear();
	}
	
	public boolean addBean(DiseaseRecordBean bean){
		boolean result= beanList.add(bean);
		return result;
	}
	
	public void removeBean(int position){
		beanList.remove(position);
		this.notifyDataSetChanged();
	}	

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		// TODO Auto-generated method stub
		ViewHolder holder;
		if (arg1==null) {
			holder=new ViewHolder();
			arg1=View.inflate(context, R.layout.disease_record_list_item, null);
			holder.tvTime=(TextView) arg1.findViewById(R.id.tv_time);
			holder.tvComplain=(TextView) arg1.findViewById(R.id.tv_complain);
			
			arg1.setTag(holder);
		} else {
			holder=(ViewHolder) arg1.getTag();
		}
		
		DiseaseRecordBean bean=getItem(arg0);
		
		holder.tvTime.setText(bean.getTime() == null ? "" : bean.getTime());
		holder.tvComplain.setText(bean.getComplain() == null ? "" : bean.getComplain());	
		
		arg1.setTag(R.id.bean_tag, bean);
		return arg1;
	}
	
	
	private class ViewHolder{
		TextView tvTime;
		TextView tvComplain;
	}
	
	
}
